package net.bw.dy.controller;



import com.alibaba.fastjson.JSON;

import net.bw.dy.bean.*;
import net.bw.dy.utils.DateUtil;
import net.bw.dy.utils.SugarUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import net.bw.dy.service.TikTokLiveStreamService;

import java.util.List;
import java.util.Map;

/**
 * @ClassName：TikTokLiveStreamController
 * @Author: Vvn
 * @Date: 2025/5/28 10:26
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@RestController
@RequestMapping("/TikTok/LiveStream")
public class TikTokLiveStreamController {

    private static final String DATA_DEFAULT_VALUE = "1970-07-01";

    @Autowired
    private TikTokLiveStreamService tikTokLiveStreamService;


    @RequestMapping("/OnlineUserCount")
    private Map getOnlineUserCount(@RequestParam(value = "date", defaultValue = DATA_DEFAULT_VALUE)
                                      String date) throws Exception {


        if (date.equals(DATA_DEFAULT_VALUE)) {
            date = DateUtil.nowDate();
        }

        System.out.println(date);

        List<OnlineUserCountResult> onlineUserCount = tikTokLiveStreamService.getOnlineUserCount(date);
        if (onlineUserCount == null || onlineUserCount.isEmpty()) {
            return null;
        }

        for (OnlineUserCountResult onlineUserCountResult : onlineUserCount) {

            System.out.println(onlineUserCountResult.getRoomId() + ":" + onlineUserCountResult.getUserCount());
        }


        return SugarUtil.getFlipNumberData(onlineUserCount.get(0).getUserCount());
    }


    @RequestMapping("/GiftIncome")
    private String getGiftIncome(@RequestParam(value = "date", defaultValue = DATA_DEFAULT_VALUE)
                                 String date) throws Exception {


        if (date.equals(DATA_DEFAULT_VALUE)) {
            date = DateUtil.nowDate();
        }

        System.out.println(date);

        List<GiftIncomeResult> giftIncome = tikTokLiveStreamService.getGiftIncome(date);
        if (giftIncome == null || giftIncome.isEmpty()) {
            return "[]";
        }
        return JSON.toJSONString(giftIncome);

    }


    @RequestMapping("/MessagePopularity")
    private String getMessagePopularity(@RequestParam(value = "date", defaultValue = DATA_DEFAULT_VALUE)
                                        String date) throws Exception {


        if (date.equals(DATA_DEFAULT_VALUE)) {
            date = DateUtil.nowDate();
        }

        System.out.println(date);

        List<MessagePopularityResult> messagePopularity = tikTokLiveStreamService.getMessagePopularity(date);
        if (messagePopularity == null || messagePopularity.isEmpty()) {
            return "[]";
        }
        return JSON.toJSONString(messagePopularity);

    }


    @RequestMapping("/AlertGift")
    private String getAlertGift(@RequestParam(value = "date", defaultValue = DATA_DEFAULT_VALUE)
                                String date) throws Exception {

        if (date.equals(DATA_DEFAULT_VALUE)) {
            date = DateUtil.nowDate();
        }

        System.out.println(date);

        List<AlertGiftResult> alertGift = tikTokLiveStreamService.getAlertGift(date);
        if (alertGift == null || alertGift.isEmpty()) {
            return "[]";
        }
        return JSON.toJSONString(alertGift);

    }


    @RequestMapping("/MessageCheck")
    private String getMessageCheck(@RequestParam(value = "date", defaultValue = DATA_DEFAULT_VALUE)
                                   String date) throws Exception {


        if (date.equals(DATA_DEFAULT_VALUE)) {
            date = DateUtil.nowDate();
        }

        System.out.println(date);

        List<MessageCheckResult> messageCheck = tikTokLiveStreamService.getMessageCheck(date);
        if (messageCheck == null || messageCheck.isEmpty()) {
            return "[]";
        }
        return JSON.toJSONString(messageCheck);

    }

}
